package com.ktwlsoft.archivemanage.domain.business.repositoryService.view;

import com.ktwlsoft.archivemanage.domain.business.repositoryService.NotifySetRepositoryService;
import com.ktwlsoft.archivemanage.domain.dao.entity.NotifySet;
import com.ktwlsoft.archivemanage.domain.dao.entity.view.ProfileMendExceed;
import com.ktwlsoft.archivemanage.domain.dao.repository.view.ProfileMendExceedMapper;
import com.ktwlsoft.archivemanage.domain.dao.repository.view.ProfileMendTimesMapper;
import com.ktwlsoft.archivemanage.domain.dao.repository.view.ProfileMendTimesVariationMapper;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MendDataProfileRepositoryService {

    @Getter
    private final ProfileMendExceedMapper profileMendExceedMapper;

    @Getter
    private final ProfileMendTimesMapper profileMendTimesMapper;

    @Getter
    private final ProfileMendTimesVariationMapper profileMendTimesVariationMapper;

    @Getter
    private final NotifySetRepositoryService notifySetRepositoryService;

    public MendDataProfileRepositoryService(ProfileMendExceedMapper profileMendExceedMapper, ProfileMendTimesMapper profileMendTimesMapper, ProfileMendTimesVariationMapper profileMendTimesVariationMapper, NotifySetRepositoryService notifySetRepositoryService) {
        this.profileMendExceedMapper = profileMendExceedMapper;
        this.profileMendTimesMapper = profileMendTimesMapper;
        this.profileMendTimesVariationMapper = profileMendTimesVariationMapper;
        this.notifySetRepositoryService = notifySetRepositoryService;
    }

    public List<ProfileMendExceed> getExceed() {
        NotifySet mendNotifySet = notifySetRepositoryService.findByName("MEND_WARNING");
        int mendWarningCount = mendNotifySet.getNotifyPeriod();
        String unit = mendNotifySet.getNotifyPeriodUnit().toString();
        return profileMendExceedMapper.selectAll(mendWarningCount, unit);
    }

    public List<ProfileMendExceed> getSelfOrRepeatExceed() {
        NotifySet mendNotifySet = notifySetRepositoryService.findByName("MEND_WARNING");
        int mendWarningCount = mendNotifySet.getNotifyPeriod();
        String unit = mendNotifySet.getNotifyPeriodUnit().toString();
        return profileMendExceedMapper.selectAll(mendWarningCount, unit);
    }
}
